package com.fis.hlo.pm.client;

import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import com.fis.hlo.pm.invoicereport.InvoiceReportTransfererService;
import com.fis.hlo.pm.invoicereport.PMInvoiceReportTransferer;
import com.fis.mca.config.Config;
import com.fis.mca.config.ConfigConstant;

public class InvoiceReportTransfererClient {
	private static final QName SERVICE_NAME = new QName(
			"http://invoicereport.pm.hlo.fis.com/",
			"InvoiceReportTransfererService");
	private static final String WSDL_URL = Config
			.getURL(ConfigConstant.PM_INVOICE_REPORT_PORT_KEY);

	public static PMInvoiceReportTransferer getService() throws Exception {
		URL url = new URL(WSDL_URL);
		InvoiceReportTransfererService ss = new InvoiceReportTransfererService(
				url, SERVICE_NAME);
		PMInvoiceReportTransferer port = ss.getInvoiceReportTransfererPort();

		Client client = ClientProxy.getClient(port);
		HTTPConduit http = (HTTPConduit) client.getConduit();
		HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
//		httpClientPolicy.setConnectionTimeout((15 * 60) * 1000);
		httpClientPolicy.setReceiveTimeout((25 * 60) * 1000);
		
		httpClientPolicy.setAllowChunking(false);
		http.setClient(httpClientPolicy);

		return port;
	}
}
